@extends('shop::layouts.master')
@section('title')
    添加价目表
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">

                @foreach($arr_specs as $key=>$value)
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>{{$value['name']}}</label>
                        <div class="layui-input-inline">
                            <select name="specs_ids[]">
                                @foreach($value['_child'] as $ka=>$va)
                                    <option value="{{$va['id']}}">{{$va['name']}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                @endforeach

                <div class="layui-form-item">
                    <label for="L_price" class="layui-form-label">
                        <span class="x-red">*</span>价格</label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_price" name="price" required="" lay-verify="price"  autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="add" lay-submit="">增加</button></div>
            </form>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>

        layui.use(['form', 'layer','layedit','jquery'],
            function() {

                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer,
                    layedit = layui.layedit;

                //创建一个编辑器
                var editIndex = layedit.build('LAY_demo_editor');

                //自定义验证规则
                form.verify({
                    price: function(value) {
                        if (value.length > 6) {
                            return '不能超过6个字符啊';
                        }
                        layedit.sync(editIndex);
                    },
                });

                //监听提交
                form.on('submit(add)',
                    function(data) {
                        var $_url = '{{route('shop_check_product_store')}}';
                        var $_data = data.field;

                        $.ajax({
                            url:$_url,
                            type:'post',
                            data:$_data,
                            dataType : "json",
                            success:function(result){
                                if(result.state === 0){
                                    layer.msg(
                                        "增加成功",
                                        {time:1000,icon: 6},
                                        function() {
                                            //关闭当前frame
                                            xadmin.close();

                                            // 可以对父窗口进行刷新
                                            xadmin.father_reload();
                                        });
                                }else{
                                    layer.msg(result.msg, {time:2000,icon: 5});
                                }

                            }});
                        return false;

                    });

            });
    </script>
@endsection




